package day21.fefei;

import java.io.IOException;
import java.net.*;

public class sendUDP {
    public static void main(String[] args) throws Exception {
        String str="你好";
        InetAddress address=InetAddress.getLocalHost();
        DatagramPacket dp = new DatagramPacket(str.getBytes(), str.getBytes().length, address, 8088);
        DatagramSocket ds=new DatagramSocket();
        ds.send(dp);
        ds.close();
    }
}
class ReceiveUDP{
    public static void main(String[] args) throws IOException {
        byte[] bytes=new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        DatagramSocket ds = new DatagramSocket(8088);
        ds.receive(dp);
        byte[] content=dp.getData();
        System.out.println(new String(content,0,dp.getLength()));
        int port=dp.getPort();
        InetAddress address = dp.getAddress();
        System.out.println(address);

        System.out.println(port);
        ds.close();
    }

}